package lay
{
	import control.ChangeDirectionPoint;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.text.StaticText;
	
	import myutils.LoadManager;
	import myutils.PxChangeUtils;

	public class Map extends Sprite
	{
		public static var gridNum_x:int = 16;
		public static var gridNum_y:int = 24;
		public static var background_x:int;
		public static var background_y:int;
		public static var gridSize:int;
		public static var frame:int = 30;
		public var changes:ChangeDirectionPoint;
		
		
		
		
		public function Map(type:String)
		{
			initSize();
			
			initGrid();
			
			initMapData(type);
			
			
			
		}
		
		private function initMapData(type:String):void
		{
						
		}
		
		private function initGrid():void
		{
			var backgroudSprite:Sprite = new Sprite();
			backgroudSprite.graphics.lineStyle(1,0x000000,0.8)
			backgroudSprite.graphics.beginFill(0x808080,0.8);
			backgroudSprite.graphics.drawRoundRect(0,0,Demo.WIDTH,Demo.HEIGHT,8);
			backgroudSprite.graphics.endFill();
			this.addChild(backgroudSprite);
			
			var gridBackGroud:Sprite = new Sprite();
			gridBackGroud.graphics.lineStyle(1,0x000000,0.8)
			gridBackGroud.graphics.beginFill(0x008080,0.8);
			gridBackGroud.graphics.drawRoundRect(0,0,background_x,background_y,8);
			gridBackGroud.graphics.endFill();
			gridBackGroud.x = (Demo.WIDTH - background_x)/2;
			gridBackGroud.y = (Demo.HEIGHT - background_y)/2;
			this.addChild(gridBackGroud);
			
			/**
			
			var backgroud:BitmapData = LoadManager.getInstance().getBitmapData("010.jpg");
			var backgroudSprite:Sprite = new Sprite();
			var bmap1:Bitmap = new Bitmap(backgroud);
			this.addChild(bmap1);
			bmap1.width = Demo.WIDTH;
			bmap1.height = Demo.HEIGHT;
			var bmap:Bitmap = new Bitmap(backgroud);
			bmap.width = background_x;
			bmap.height = background_y;
			backgroudSprite.x = (Demo.WIDTH - background_x)/2;
			backgroudSprite.y = (Demo.HEIGHT - background_y)/2;
			backgroudSprite.addChild(bmap);
			this.addChild(backgroudSprite);
			*/
			var gridImage:BitmapData = LoadManager.getInstance().getBitmapData("blueGrid.jpg");
			var grid:Bitmap = new Bitmap(gridImage);
			grid.width = gridSize;
			grid.height = grid.width;
			
			for(var i:int=0;i<gridNum_x;i++)
			{
				for(var j:int=0;j<gridNum_y;j++)
				{
					var grid0:Bitmap = new Bitmap(gridImage.clone());
					grid0.width = grid.width;
					grid0.height = grid.height;
					grid0.x = (grid0.width) * i;
					grid0.y = (grid0.height) * j;
					gridBackGroud.addChild(grid0);
				}
			}
		}
		
		private function initSize():void
		{
			var x_max:int = (Demo.WIDTH - frame)/gridNum_x;
			var y_max:int = (Demo.HEIGHT - frame)/gridNum_y;
			gridSize = x_max<y_max?x_max:y_max;
			
			background_x = gridNum_x * gridSize;
			background_y = gridNum_y * gridSize;
		}
	}
}